include etc/details.mk  # must be loaded AFTER your first rule

data=    autompg
main=    dash
GawkVer= gawk-4.0.1
pretty = gawk -f bin/malign.awk

crs : code
	$(foreach e, $(Effort), \
	    gauk cr -d data/$e.csv > $(HOME)/tmp/cr_$e.txt;)
	bash bin/cr.sh

Effort=coc81 finnish nasa93c2 telecom albrecht \
       coc81e nasa93c5 coc81o nasa93 \
       coc81sd kemerer miyazaki94 sdr china desharnais \
       nasa93c1


nbcs : code
	gauk nbc -train data/weatherd.csv    -x  3 -m 1 -k 2 | $(pretty)
	gauk nbc -train data/contactlens.csv -x  3 -m 1 -k 2 | $(pretty)
	gauk nbc -train data/audiology.csv   -x 10 -m 1 -k 2 | $(pretty)
	gauk nbc -train data/soybean.csv     -x 10 -m 1 -k 2 | $(pretty)
	gauk nbc -train data/hypothyroid.csv -x 10 -m 1 -k 2 | $(pretty)



anovad     : ready; $(Go)
readnums   : ready; $(Go)
tiles      : ready; $(Go)
sk0 : ready; gauk scottknott _scottknott -d  data/gots/sc0 -f " %6.2f" -h 1
sk1 : ready; gauk scottknott _scottknott -d  data/gots/sc1 
sk2 : ready; gauk scottknott _scottknott -d  data/gots/sc2 -f " %6.2f" -l 98 -h 102
sk4 : ready; gauk scottknott _scottknott -d  data/gots/comba -f "%3s" -l 0 -h 100 -w 100
sk5 : ready; gauk scottknott _scottknott -d  data/gots/combap -f "%3s" -l 0 -h 100 -w 100

args       : ready
	gauk  lib.awk _args -g 22 --open -f 100 --h

define knn
	$(MAKE) ready
	mkdir -p data/gots/knn
	rm -f  data/gots/knn/$(strip $1)* 
	$(foreach k,1 2 4 8, \
	    echo $1 $k >&2; \
	    gauk   knn _knn -d data/$(strip $1).csv  -seed $2 -k $k -pre ",k=$k" \
         >>  data/gots/knn/$(strip $1)1.csv ; \
	    gauk   knn _knn -d data/$(strip $1).csv  -seed $2 -k $k --n   -pre ",k=$k"\
         >>  data/gots/knn/$(string $1)0.csv
  ) 
endef


define dash
	$(MAKE) ready
	gauk  dash _dash data/$(strip $1).csv $2 $3 $4 $5 $6
endef

ega1: ready
	gauk  -f readcsv.awk Readcsv



eg00: ready eg1 eg2 eg3 eg4 eg5 eg6 eg7	
	gauk scottknott _scottknott -d  data/gots/knn -f "%5s" -l 1 -h 300 -w 30

eg1:; $(call knn, nasa93,     $(Seed)) 
eg2:; $(call knn, desharnais, $(Seed))
eg3:; $(call knn, autompg,    $(Seed))
eg4:; $(call knn, miyazaki94, $(Seed))
eg5:; $(call knn, coc81,      $(Seed))
eg6:; $(call knn, finnish,    $(Seed))
eg7:; $(call knn, china,      $(Seed))
eg8:; $(call knn, autompg50K, $(Seed))

eg10: eg11a eg11b eg12a eg12b eg13a eg13b eg14a eg14b \
      eg15a eg15b eg16a eg16b eg17a eg17b 

define egDashWorker
	$(call dash, $1, $(Seed),      20,20,1,1) > $(Tmp)/$1_dash20_20_prunew.csv
	$(call dash, $1, $(Seed),      20,20,0,1) > $(Tmp)/$1_dash20_20_noprunew.csv
	$(call dash, $1, $(Seed),       3,20,1,1)  > $(Tmp)/$1_dash3_20_prunew.csv
	$(call dash, $1, $(Seed),       3,20,0,1)  > $(Tmp)/$1_dash3_20_noprunew.csv
	###
	gauk knn.awk knn $(Tmp)/$1_dash20_20_prunew.csv   $(Seed) 1
	gauk knn.awk knn $(Tmp)/$1_dash20_20_noprunew.csv $(Seed) 1
	gauk knn.awk knn $(Tmp)/$1_dash3_20_prunew.csv    $(Seed) 1
	gauk knn.awk knn $(Tmp)/$1_dash3_20_noprunew.csv  $(Seed) 1
	##
	$(call dash, $1, $(Seed),      20,20,1,0) > $(Tmp)/$1_dash20_20_prune.csv
	$(call dash, $1, $(Seed),      20,20,0,0) > $(Tmp)/$1_dash20_20_noprune.csv
	$(call dash, $1, $(Seed),       3,20,1,0)  > $(Tmp)/$1_dash3_20_prune.csv
	$(call dash, $1, $(Seed),       3,20,0,0)  > $(Tmp)/$1_dash3_20_noprune.csv
	###
	gauk knn.awk knn $(Tmp)/$1_dash20_20_prune.csv   $(Seed) 1
	gauk knn.awk knn $(Tmp)/$1_dash20_20_noprune.csv $(Seed) 1
	gauk knn.awk knn $(Tmp)/$1_dash3_20_prune.csv    $(Seed) 1
	gauk knn.awk knn $(Tmp)/$1_dash3_20_noprune.csv  $(Seed) 1
endef

define dashing
  $(MAKE) ready
	bash bin/dashing $(strip $1)
endef

eg11:  
	rm -f data/gots/dashing/*
	$(MAKE) eg11a eg11b eg11c eg11d eg11e eg11f
	gauk scottknott _scottknott -d  data/gots/dashing -f "%4s" -l 0 -h 300 -w 20

eg11a:;$(call dashing,nasa93)
eg11b:;$(call dashing,desharnais)
eg11c:;$(call dashing,miyazaki94)
eg11d:;$(call dashing,coc81)
eg11e:;$(call dashing,finnish)
eg11f:;$(call dashing,china)

define splots
	$(MAKE) ready
	gauk cube _cube --dump -d data/$(strip $1).csv -p 10 -seed $(RANDOM) -m 3 > ~/tmp/$(strip $1).csv
	bash bin/splots $(strip $1) ~/tmp/$(string $1).csv
endef

fred:
	echo "["$(Seed)"]"

hack2: ; $(call splots,rand)
hacka:;$(call splots,nasa93)
hackb:;$(call splots,desharnais)
hackc:;$(call splots,miyazaki94)
hackd:;$(call splots,coc81)
hacke:;$(call splots,finnish)
hackf:;$(call splots,china)

# define knnnew
# 	$(MAKE) ready
# 	mkdir -p data/gots/cube1
# 	rm -f  data/gots/cube1/$(strip $1)*
# 	$(foreach p,1 10,\
# 	$(foreach m,2 3 4  6,\
# 	    gauk cube _cube -d $2 -p $p -seed $(Seed) -m $m > ~/tmp/$(strip $1).csv; \
# 		  $(foreach k,1 2 4,                    \
# 	       echo $1 $k >&2;                      \
# 	       gauk   knn _knn -d ~/tmp/$(strip $1).csv -seed $(Seed) -k $k -pre "m=$m,p=$p"    >> data/gots/cube1/$(strip $1)1.csv;\
#        )))
#endef

# gauk   knn _knn -d ~/tmp/$(strip $1).csv -seed $(Seed) -k $k -pre "m=$m" --n >> data/gots/cube1/$(strip $1)0.csv; 

knnneweg :
	mkdir -p data/gots/cube1
	rm -f  data/gots/cube1/*
	bash bin/cubing albrecht
	bash bin/cubing china
	bash bin/cubing coc81
	bash bin/cubing coc81e
	bash bin/cubing coc81o
	bash bin/cubing coc81sd
	bash bin/cubing desharnais
	bash bin/cubing finnish
	bash bin/cubing kemerer
	bash bin/cubing miyazaki94
	bash bin/cubing nasa93
	bash bin/cubing nasa93c1
	bash bin/cubing nasa93c2
	bash bin/cubing nasa93c5
	bash bin/cubing sdr
	bash bin/cubing telecom
	gauk scottknott _scottknott -d data/gots/cube1 -h 2000 -w 50 -f "%6s"

define cubed
	gauk cube _cube --dump -d data/$1.csv -p 1 -seed $RANDOM -m 3 
endef


testingdata:
	$(call cubed,albrecht)
	$(call cubed,china)
	$(call cubed,coc81)
	$(call cubed,coc81e)
	$(call cubed,coc81o)
	$(call cubed,coc81sd)
	$(call cubed,desharnais)
	$(call cubed,finnish)
	$(call cubed,kemerer)
	$(call cubed,miyazaki94)
	$(call cubed,nasa93)
	$(call cubed,nasa93c1)
	$(call cubed,nasa93c2)
	$(call cubed,nasa93c5)
	$(call cubed,sdr)
	$(call cubed,telecom)

define splotsed
	bash bin/splots $1
endef

plottingData:
	$(call splotsed,albrecht)
	$(call splotsed,china)
	$(call splotsed,coc81)
	$(call splotsed,coc81e)
	$(call splotsed,coc81o)
	$(call splotsed,coc81sd)
	$(call splotsed,desharnais)
	$(call splotsed,finnish)
	$(call splotsed,kemerer)
	$(call splotsed,miyazaki94)
	$(call splotsed,nasa93)
	$(call splotsed,nasa93c1)
	$(call splotsed,nasa93c2)
	$(call splotsed,nasa93c5)
	$(call splotsed,sdr)
	$(call splotsed,telecom)


